{include file="header/index" /}
<div class="container announcementwrap">
	{include file="common@public/alert" /}
	<form class="form-inline" id="searchForm" action="{:url('Announcement/index')}" method="post">
		<div class="mt20 mb20 choicelist clearfix">
			<button type="button" class="btn btn-default delbtn input-Btn" id="delete">删除&nbsp;&nbsp;<i class="glyphicon glyphicon-remove"></i></button>
			<select class="t_center input-min" name="">
				<option class="t_center">标题</option>
			</select>
			<input class="input-min" type="text" id="key" name="key" value="{$vals}" />
			<button type="submit" class="btn btn-default searchbtn input-Btn"><i class="glyphicon glyphicon-search"></i>&nbsp;&nbsp;搜索</button>
			<a href="{:url('Announcement/add')}"><button type="button" class="btn btn-primary addbtn ml30 input-Btn" style="float: right;"><i class="glyphicon glyphicon-plus"></i>&nbsp;&nbsp;新增公告</button></a>
		</div>
	</form>
	<form id="form1" method="Post">
		<table class="table table-striped announcement_table">
			<tr>
				<th><input type="checkbox" onclick="checkAll(this)" id="all" /></th>
				<th>标题</th>
				<th>创建人</th>
				<th>更新时间</th>
				<th>当前状态</th>
				<th>操作</th>
			</tr>
			<script id="list-template" type="text/html">
				{{# for(var i=0;i
				<d.length;i++){ }} <tr>
					<td><input class="list" type="checkbox" name="announcement_id[]" onclick="selectAll(this)" value="{{d[i].announcement_id}}" /></td>
					<td>
						<p class="announcement_title">{{d[i].title}}</p>
					</td>
					<td>{{d[i].role_id}}</td>
					<td>{{d[i].update_time}}</td>
					<td>
						{{# if(d[i].status==1){ }}
						<a class="red" href="javascript:;" onclick="note_status({{d[i].announcement_id}});">
							<div id="zt{{d[i].announcement_id}}"><span class="label label-info">发布中</span></div>
						</a>
						{{# }else{ }}
						<a class="red" href="javascript:;" onclick="note_status({{d[i].announcement_id}});">
							<div id="zt{{d[i].announcement_id}}"><span class="label label-danger">停用</span></div>
						</a>
						{{# } }}
					</td>
					<td>
						<a href="{:url('Announcement/check')}?id={{d[i].announcement_id}}">查看</a>
						<a href="{:url('Announcement/edit')}?announcement_id={{d[i].announcement_id}}">编辑</a>
					</td>
					</tr>
					{{# } }}
			</script>
			<tbody id="list-content"></tbody>
		</table>
	</form>
	<div class="clearfix" style="float:right;margin: 0 auto;">
		<span class="fl mt5">共{$count}条数据</span><span id="allpage" class="fl  mr20 mt5"></span><span class="fl" id="AjaxPage"></span>
	</div>
	<!-- 加载动画 -->
	<div class="spiner-example">
		<div class="sk-spinner sk-spinner-three-bounce">
			<div class="sk-bounce1"></div>
			<div class="sk-bounce2"></div>
			<div class="sk-bounce3"></div>
		</div>
	</div>

</div>
</body>
<script type="text/javascript">
	function checkAll(obj) {
		//获取name=box的复选框
		if($(obj).is(":checked")) {
			$(".list").prop("checked", true);
		} else {
			$(".list").prop("checked", false);
		}
	}

	function selectAll() {
		//获取name=box的复选框
		var userids = document.getElementsByClassName("list");
		var count = 0;
		//遍历所有的复选框
		for(var i = 0; i < userids.length; i++) {
			if(userids[i].checked) {
				count++;
			}
		}
		//选中复选框的个数==获取复选框的个数
		if(count == userids.length) {
			//设置id为all复选框选中
			document.getElementById("all").checked = true;
		} else {
			//设置id为all复选框不选中
			document.getElementById("all").checked = false;
		}

	}
	$('#delete').click(function() {
		var userids = document.getElementsByClassName("list");
		var count = 0;
		//遍历所有的复选框
		for(var i = 0; i < userids.length; i++) {
			if(userids[i].checked) {
				count++;
			}
		}
		if(count < 1) {
			layer.msg('没有选择数据!', {
				time: 1000, //20s后自动关闭
			});
			return;
		}
		if(confirm('确认要删除吗？')) {
			$("#form1").attr('action', '{:url("Announcement/delete")}');
			$("#form1").submit();
		} else {
			return false;
		}
	});

	//laypage分页
	Ajaxpage();

	function Ajaxpage(curr) {
		var key = $('#key').val();
		$.getJSON('{:url("Announcement/index")}', {
			page: curr || 1,
			key: key
		}, function(data) {
			$(".spiner-example").css('display', 'none'); //数据加载完关闭动画
			if(data == '') {
				$("#list-content").html('<td colspan="20" style="padding-top:10px;padding-bottom:10px;font-size:16px;text-align:center">暂无数据</td>');
			} else {
				var tpl = document.getElementById('list-template').innerHTML;
				laytpl(tpl).render(data, function(html) {
					document.getElementById('list-content').innerHTML = html;
				});

				laypage({
					cont: $('#AjaxPage'), //容器。值支持id名、原生dom对象，jquery对象,
					pages: '{$allpage}', //总页数
					skip: true, //是否开启跳页
					skin: '#337ab7', //分页组件颜色
					curr: curr || 1,
					first: '首页', //若不显示，设置false即可
					last: '尾页', //若不显示，设置false即可
					groups: 3, //连续显示分页数
					jump: function(obj, first) {
						if(!first) {
							Ajaxpage(obj.curr)
						}
						$('#allpage').html('，第' + obj.curr + '页，共' + '<i>' + obj.pages + '</i>' + '页');
						inputlength();
					}
				});
			}
		});
	}

	//状态
	function note_status(id) {
		info.status(id, '{:url("status")}');
	}
</script>

</html>